var layer //弹层
    ,table //表格
    ,form  //表单
    ,$ //JQuery
    ,rowsData = new Array()
    ,id = RequestURLParam.getParam("id") || ''
    ,type = RequestURLParam.getParam("type") || ''
    ,parentId = RequestURLParam.getParam("parentId") || ''
    ,enName = RequestURLParam.getParam("enName") || '';

layui.config({
    version: '1545041465443' //为了更新 js 缓存，可忽略
});

layui.use(['form', 'layer', 'table', 'jquery'], function(){
    layer = layui.layer //弹层
    table = layui.table //表格
    form = layui.form //表单
    $ = layui.$ //JQuery

    $(document).ready(function () {
        $('#dictionaryId').val(id);
        $('#parentId').val(parentId);
        $('#enName').val(enName);
        if(type == "edit"){
            ActHttpRequest("/wf/dictionary/findById",{"id":id},function (data) {
                var wd = data.wfDictionary;
                $('#cnName').val(wd.cnName);
                $('#remark').val(wd.remark);
                $('#value').val(wd.value);
            })
        }
    });

    //监听提交
    form.on('submit(save)', function(data){
        submitData(data);
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        return false;
    });
});


/*
*  提交数据
* */
function submitData(data){
    var param = data.field;
    if(type == "edit"){
        ActHttpRequest("/wf/dictionary/updateData", param, function (data) {
            if(data.OK == "OK"){
                var iframe = RequestURLParam.getParam("iframeId");
                $('#'+iframe,parent.document)[0].contentWindow.recGrid(parentId);
            }else{
                parent.layer.msg("修改失败！请重新添加");
            }
        });
    }else if(type == "add"){
        ActHttpRequest("/wf/dictionary/insert", param, function (data) {
            if(data.OK == "OK"){
                var iframe = RequestURLParam.getParam("iframeId");
                $('#'+iframe,parent.document)[0].contentWindow.recGrid(parentId);
            }else{
                parent.layer.msg("添加失败！请重新添加");
            }
        });
    }

}
